﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using kim.Common;
namespace kim.UI
{
    public class BasePage : System.Web.UI.Page
    {
        protected int fid, typeid;
        protected string title, toptitle, webPath;

        protected override void OnPreLoad(EventArgs e)
        {
            base.OnPreLoad(e);
            GetSeo();
            typeid = kim.Common.KIMRequest.GetInt("typeid", 1);
            fid = kim.Common.KIMRequest.GetInt("fid", 1);
            GetTitle(typeid);
            
        }
        /// <summary>
        /// About页面获取标题
        /// </summary>
        /// <param name="typeid">类型</param>
        /// <returns>返回标题</returns>
        protected string GetTitle(int typeid)
        {


            if (fid == 1)
            {

                        title = "公司简介";

            }
            if (fid == 7)
            {
                title = "技能考试";
            }
            if (fid == 8)
            {
                title = "企业合作";
            }
            if (fid == 9)
            {
                title = "联系我们";
            }
            return title;
        }

        /// <summary>
        /// 获取banner图
        /// </summary>
        /// <returns></returns>
        protected List<Model.Show> GetSlide(int top, int typeid, int channelID)
        {
            List<Model.Show> slide = new BLL.Show().GetModelList(top,"typeid="+typeid+" and ChannelID="+channelID+"","sort asc");
            return slide;
        }

        /// <summary>
        /// 获取内容页
        /// </summary>
        /// <param name="typeidx">类型</param>
        /// <param name="fidx">频道</param>
        /// <returns></returns>
        public static string GetAboutText(int typeidx, int fidx)
        {
            string SlideText = string.Empty;
            List<Model.WebInfo> slide = new BLL.WebInfo().GetModelList("TypeID=" + typeidx + " and ChannelID=" + fidx);
            if (slide.Count > 0)
            {
                foreach (Model.WebInfo show in slide)
                {
                    SlideText += show.Content;
                }
            }
            return SlideText;
        }

        /// <summary>
        /// 获取新闻列表
        /// </summary>
        /// <param name="typeidx">类型</param>
        /// <param name="fidx">频道</param>
        /// <returns></returns>
        protected string GetNewListServer(int top,int typeidx, int fidx)
        {
            string SlideText = string.Empty;
            List<Model.eg_news> slide = new BLL.eg_news().GetModelList(top, "ClassID=" + typeidx + " and ChannelID=" + fidx, "Sort Desc");
            int i = 0;
            if (slide.Count > 0)
            {
                foreach (Model.eg_news show in slide)
                {
                    SlideText += " <li><a href=\"service.aspx?fid=3#" + i + "\" title=\"" + show.Name + "\">" + kim.Common.Utils.CutString(show.Name, 25) + "<span>" + show.EnName + "</span></a></li>";
                    i++;
                }
            }
            return SlideText;
        }
        /// <summary>
        /// 获取新闻列表
        /// </summary>
        /// <param name="top">显示行数</param>
        /// <param name="typeidx">类型</param>
        /// <param name="fidx">频道</param>
        /// <returns></returns>
        public  List<Model.eg_news> GetNewsList(int top, int typeidx, int fidx)
        {
            string SlideText = string.Empty;
            return  new BLL.eg_news().GetModelList(top, "ClassID=" + typeidx + " and ChannelID=" + fidx, "Sort Desc");
            
        }
        #region 分类操作

        /// <summary>
        /// 获取顶级分类
        /// </summary>
        /// <param name="fid"></param>
        /// <returns></returns>
        protected IList<kim.Model.CClass> GetTopClass(int top, int fid)
        {
            return new BLL.CClass().GetTopCClass(top, "channelID=" + fid + "and ParentID=0", "orders desc");
        }
        /// <summary>
        /// 获取子级分类
        /// </summary>
        /// <param name="fid"></param>
        /// <returns></returns>
        protected IList<kim.Model.CClass> GetChildClass(int top, int fid)
        {
            return new BLL.CClass().GetTopCClass(top, "channelID=" + fid + "and ParentID!=0", "orders desc");
        }

        /// <summary>
        /// 根据父级获取分类
        /// </summary>
        /// <param name="fid"></param>
        /// <returns></returns>
        protected IList<kim.Model.CClass> GetChildByToClass(int top, int fid, int ParentID)
        {
            return new BLL.CClass().GetTopCClass(top, "channelID=" + fid + "and ParentID=" + ParentID, "orders desc");
        }

        #endregion

        protected DataSet GetProductList(int Top, string strWhere, string filedOrder)
        {
            return new BLL.Product().GetList(Top, strWhere, filedOrder);
        }

        
        /// <summary>
        /// 获取Seo
        /// </summary>
        private void GetSeo()
        {
            BLL.siteconfig bll = new BLL.siteconfig();
            Model.siteconfig model = bll.loadConfig(Utils.GetXmlMapPath(KIMKeys.FILE_SITE_XML_CONFING));
            webPath = model.webpath;
            ViewState["title"] = model.webtitle;
            ViewState["key"] = model.webkeyword;
            ViewState["desc"] = model.webdescription;
        }

    }
}